package com.itcam.cm.order.controller;

import com.itcam.cm.model.dto.order.OrderInfoDto;
import com.itcam.cm.model.entity.order.OrderInfo;
import com.itcam.cm.model.vo.common.Result;
import com.itcam.cm.model.vo.order.TradeVo;
import com.itcam.cm.order.service.OrderInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/order/orderInfo")
@RestController
public class OrderInfoController {

    @Autowired
    OrderInfoService orderInfoService;

    @GetMapping("/auth/getOrderByOrderNo/{orderNo}")
    OrderInfo getOrderByOrderNo(@PathVariable String orderNo){
        return orderInfoService.getOrderByOrderNo(orderNo);
    }

    @GetMapping("auth/{page}/{limit}")
    public Result<PageInfo<OrderInfo>> list(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            Integer orderStatus) {
        PageInfo<OrderInfo> pageInfo = orderInfoService.findOrderPage(page, limit, orderStatus);
        return Result.ok(pageInfo);
    }


    @GetMapping("auth/{orderId}")
    public Result<OrderInfo> getOrderById(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderInfoService.getOrderById(orderId);
        return Result.ok(orderInfo);
    }

    @PostMapping("auth/submitOrder")
    public Result submitOrder(@RequestBody OrderInfoDto orderInfoDto) {
        Long orderId = orderInfoService.submitOrder(orderInfoDto);
        return Result.ok(orderId);
    }

    @GetMapping("auth/buy/{skuId}")
    public Result<TradeVo> buy(@PathVariable Long skuId) {
        TradeVo tradeVo = orderInfoService.buy(skuId);
        return Result.ok(tradeVo);
    }

    @GetMapping("auth/trade")
    public Result<TradeVo> trade() {
        TradeVo tradeVo = orderInfoService.getTrade();
        return Result.ok(tradeVo);
    }


}
